package com.xujiang.mytool.GlideTest.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xujiang.common_adapter.base.BaseRecyclerAdapter;
import com.xujiang.common_adapter.holder.BaseRecyclerViewHolder;
import com.xujiang.common_plus.util.ImageUtils;
import com.xujiang.mytool.GlideTest.model.GlideMode;
import com.xujiang.mytool.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author xujiang
 * @version 2017-08-09 15:50
 */
public class GlideDemoAdapter extends BaseRecyclerAdapter<GlideMode, GlideDemoAdapter.GlideDemoListHolder> {
    public Activity activity;

    public GlideDemoAdapter(Context context, Activity activity) {
        super(context);
        this.activity = activity;
    }

    @Override
    public GlideDemoListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflate(R.layout.view_glide_demo_recycler_view_item, parent, false);
        return new GlideDemoListHolder(view);
    }

    @Override
    public void onBindViewHolderItem(GlideDemoListHolder holder, GlideMode item, int position) {
        holder.onHandle(item, position);
    }

    class GlideDemoListHolder extends BaseRecyclerViewHolder<GlideMode> {
        @BindView(R.id.view_glide_demo_item_transform_iv)
        ImageView glideImage;
        @BindView(R.id.view_glide_demo_item_tv)
        TextView glideText;

        public GlideDemoListHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void onHandle(GlideMode item, int position) {
            glideText.setText(item.getText());
            //Glide.with(getContext()).asBitmap().load(item.getImageUrl()).into(glideImage);
            ImageUtils.get(getContext(), Glide.with(getContext()))
                    .asWhat(ImageUtils.What.Bitmap)
                    .setOptions()
                    .loadAvatar(glideImage, item.getImageUrl());
        }
    }
}
